<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>投票统计图</title>
    <style>
        #main {
            width: 920px;
            height: 480px;
        }
    </style>
</head>
<body>
    <a href="/export/">导出Excel文件</a>
    <div id="main"></div>
    <script src="https://cdn.bootcdn.net/ajax/libs/echarts/4.8.0/echarts.min.js"></script>
    <script>
        let myChart = echarts.init(document.querySelector('#main'))
        let option = {
            title: {
                text: '老师投票统计结果'
            },
            tooltip: {},
            legend: {
                data:['好评数', '差评数']
            },
            xAxis: {
                data: []
            },
            yAxis: {},
            series: [
                {
                    name: '好评数',
                    type: 'bar',
                    data: []
                },
                {
                    name: '差评数',
                    type: 'bar',
                    data: []
                }
            ]
        }
        fetch('/api/data/', {
            headers: {
                'token': localStorage.token || ''
            }
        }).then(resp => resp.json()).then(json => {
            option.xAxis.data = json.xData
            option.series[0].data = json.y1Data
            option.series[1].data = json.y2Data
            myChart.setOption(option)
        })
    </script>
</body>
</html>